var flag = false;
$(function () {
    getUserInfo();
    getSignConfig();
    $(".bottom-nav-wrapper li").click(function () {
        location.href = $(this).attr("data-url")+"?channel="+getQueryString("channel");
    });
    $(".function").click(function () {
        if($(this).attr("data-url") == "bind.html" && flag){
            Toast("已绑定");
            return;
        }
        location.href = $(this).attr("data-url")+"?channel="+getQueryString("channel");
    });
    $(".sing-btn").click(function () {
        location.href = "./sign.html?channel="+getQueryString("channel");
    });
});

function getUserInfo() {
    $.ajax({
        type:'get',
        url:BASE_URl + "user/profile",
        success:function (data) {
            if(data.success){
                DrawUserInfo(data.data);
            }
        }
    });
}

function getSignConfig() {
    $.ajax({
        type:'get',
        url:BASE_URl + "config/sign",
        success:function (data) {
            if(data.success){
                if(data.data.daily.today){
                    $(".sing-btn").html("已签到");
                }else{
                    $(".sing-btn").html("签到");
                }
            }
        }
    });
}

function DrawUserInfo(data) {
    $(".user-name").html(data.nickname);
    $(".id-num span").html(data.uid);
    var now = Date.now();
    var vipDate = data.vip_date;
    if(data.mobile != ""){
        flag = true;
        $(".bind-phone .right-wrapper").html(`<span>已绑定${data.mobile}</span>`);
    }
    if(vipDate == "" || FormatDate(now).split(" ")[0] > vipDate){
        $(".user-name").css("width","100%");
        $(".vip-detail").hide();
    }else{
        $(".end-time").html(vipDate);
    }
    $(".user-avatar-wrapper").html(`<img src='${data.avatar}'>`);
    $(".coin").html(data.coin);
    $(".gift").html(data.gift);
}